package com.tarena.lbs.stock.web.repository.Impl;

import com.tarena.lbs.pojo.stock.dos.CouponStockDO;
import com.tarena.lbs.stock.web.mapper.StockMapper;
import com.tarena.lbs.stock.web.repository.StockRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
public class StockRepositoryImpl implements StockRepository {
    @Autowired
    private StockMapper stockMapper;


    //mybatis 执行写操作的时候 update delete insert
    //会根据执行结果影响的行数 返回int数字
    public boolean initCouponStock(Integer couponId, Integer num) {
        CouponStockDO csDO=new CouponStockDO();
        csDO.setCouponId(couponId);
        csDO.setBusinessId(0);
        csDO.setNum(num);
        csDO.setCreateAt(new Date());
        csDO.setUpdateAt(csDO.getCreateAt());
        int rows=stockMapper.insert(csDO);
        //新增rows==0 新增就是失败,报错也是失败
        return rows>0;
    }

    @Override
    public boolean updateCouponNum(Integer couponId) {
        int rows=stockMapper.updateCouponNumById(couponId);
        return rows>0;
    }
}
